package org.lds.logger.config.appender;

import org.lds.logger.config.appender.rolling.RollingStrategy;
import org.lds.logger.config.filter.AbstractAppenderFilter;
import org.lds.logger.config.layout.Layout;

public class RollingFileAppender extends FileAppender {

    private RollingStrategy rollingStrategy;

    public RollingFileAppender() {
    }

    public RollingFileAppender(String name, String destination, int priority, AbstractAppenderFilter abstractAppenderFilter, Layout layout, RollingStrategy rollingStrategy) {
        super(name, destination, priority, abstractAppenderFilter, layout);
        this.rollingStrategy = rollingStrategy;
    }

    public RollingStrategy getRollingStrategy() {
        return rollingStrategy;
    }

    public void setRollingStrategy(RollingStrategy rollingStrategy) {
        this.rollingStrategy = rollingStrategy;
    }

    @Override
    protected boolean beforeAppend(String message) {
        if (rollingStrategy.rolling()) {
            rollingStrategy.execRolling();
        }
        return true;
    }
}
